package com.sec.android.app.myfiles.module.local.foldertree;

import android.content.ClipData;
import android.view.DragEvent;
import android.view.View;
import android.widget.AbsListView;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.feature.DragAndDropMgr;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.util.UiUtils;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;
import com.sec.android.app.myfiles.widget.listview.FolderTreeListViewImp;

public class FolderTreeDragAndDropImp extends AbsDragAndDrop {

    public FolderTreeDragAndDropImp(AbsMyFilesFragment fragment, AbsListViewImp listViewImp) {
        super(fragment, listViewImp);
    }

    @Override
    public boolean doDrop(ClipData clipData, int dropPosition) {
        boolean bRet = false;
        if (dropPosition != AppConstants.UNDEFINED) {
            FileRecord dstFile = mListViewImp.getFileRecord(dropPosition);
            if (dstFile != null) {
                StorageType dstType = dstFile.getStorageType();
                if (!StorageType.Category.equals(dstType)
                        && !StorageType.Downloads.equals(dstType)
                        && !StorageType.Recent.equals(dstType)
                        && !StorageType.Cloud.equals(dstType)) {
                    bRet = super.doDrop(clipData, dropPosition);
                }
            }
        }
        return bRet;
    }

    @Override
    protected boolean handleActionDragLocation(View view, DragEvent event, AbsListView listView, int position, int y) {
        Log.a(this, "ACTION_DRAG_LOCATION");
        ((FolderTreeListViewImp) mListViewImp).checkFolderTreeOpen(position);
        return super.handleActionDragLocation(view, event, listView, position, y);
    }

    @Override
    protected void ensureCurrentItemBackground(View view) {
        if (view != null) {
            if (!view.isActivated()) {
                view.setBackgroundResource(UiUtils.getSelectableItemBackground(mContext));
            } else {
                view.setBackgroundResource(R.drawable.list_item_activated_background_ripple);
            }
        }
    }

    @Override
    protected void restoreLastItemBackground(View prevView) {
        if (prevView != null) {
            prevView.setBackgroundResource(R.drawable.list_item_activated_background);
        }
    }
}
